﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Security;

namespace Konekcija.Core.Reporting.Mappings.Security
{
    public class GroupMap : ClassMap<Group>
    {
        public GroupMap()
        {
            Schema("security");
            Table("Groups");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.GroupName).Nullable();
            Map(x => x.Description).Nullable();
            Map(x => x.DateCreated).Nullable();
            Map(x => x.DateChanged).Nullable();
            Map(x => x.ByUserId).Nullable();

            // security
            HasManyToMany(x => x.Users)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("GroupId")
                .ChildKeyColumn("UserId")
                .Table("security.UsersToGroups");
        }
    }
}
